<?php
/**
 * 用户操作相关的函数接口
 */
require_once '../dr-config.php';
require_once ABSPATH . DRINC . '/dr-functions.php';

/**
 * 更新用户的积分值
 *
 * @param int $userid
 * @param int $reputation
 */
function dr_update_user_reputation_with_userid($user_id, $reputation)
{
	$posts = array(
		'action' => 'update_reputation',
		'user_id' => $user_id,
		'reputation' => $reputation
	);
	dr_server_request('dr-app-users.php', $posts);
}

function dr_get_user_profile($user_id)
{
	$posts = array(
		'action' => 'get_user_profile',
		'user_id' => $user_id
	);

	$json_result = dr_server_request('dr-app-users.php', $posts);

	return json_decode($json_result, true);
}

//echo '<pre>';
//var_dump(dr_get_user_profile(2));

function dr_get_user_profile_for_edit($user_id)
{
	$posts = array(
		'action' => 'get_user_profile_for_edit',
		'user_id' => $user_id
	);

	$json_result = dr_server_request('dr-app-users.php', $posts);

	return json_decode($json_result, true);
}

//echo '<pre>';
//var_dump(dr_get_user_profile_for_edit(2));

function dr_update_user_profile_after_edit($user_id, $profile)
{
	$posts = $profile;
	$posts['action'] = 'update_user_profile_after_edit';
	$posts['user_id'] = $user_id;

	$json_result = dr_server_request('dr-app-users.php', $posts);

	return json_decode($json_result, true);
}
